/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.attence;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.attence.DutyRegister;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-31
 */
@Service("dutyregisterService")
public class DutyRegisterServiceImpl implements DutyRegisterService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of DutyRegister
     ****************************************/
    public void insert(DutyRegister dutyregister) throws Exception {
        dutyregister.setRegisterid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(dutyregister);
    }

    /****************************************
     * Update a instace of DutyRegister
     ****************************************/
    public void update(DutyRegister dutyregister) throws Exception {
        iDataSet4iBatis.update(dutyregister);
    }

    /****************************************
     * Delete a instace of DutyRegister
     ****************************************/
    public void delete(DutyRegister dutyregister) throws Exception {
        iDataSet4iBatis.delete(dutyregister);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(DutyRegister dutyregister) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(DutyRegister dutyregister) throws Exception {
        String statementId = dutyregister.getStatmentId();
        String mainId = dutyregister.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> dutyregisterList = new ArrayList<BaseModel>();
        for (String id : ids) {
            DutyRegister model = new DutyRegister();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            dutyregisterList.add(model);
        }
        iDataSet4iBatis.batchDelete(dutyregisterList);
    }

    /****************************************
     * Query instaces of DutyRegister
     ****************************************/
    public List<BaseModel> queryAsList(DutyRegister dutyregister) throws Exception {
        String queryListStatement = "";
        if (dutyregister.isPaging()) {
            queryListStatement = dutyregister.getStatmentId();
            dutyregister.setStatmentId("DutyRegister.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(dutyregister);
            dutyregister.setTotalCount(baseModel.getTotalCount());
            dutyregister.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(dutyregister);
    }

    /****************************************
     * Query a instaces of DutyRegister
     ****************************************/
    public BaseModel queryAsObject(DutyRegister dutyregister) throws Exception {
        return iDataSet4iBatis.queryAsObject(dutyregister);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
